package com.bb.blog.security.common;

import com.bb.blog.web.component.ResponseUtil;
import com.bb.blog.web.model.CommonResponse;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CommonAuthenticationEntyPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        CommonResponse commonResponse = ResponseUtil.fail(HttpStatus.UNAUTHORIZED, "用户未登录或登录信息已过期");
        ResponseUtil.parseResponse(response, commonResponse);
    }
}
